<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_block_TabPageStructureAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$documentId = $this->getBlockContext()->getParameter("documentId");
		$documentLang = $this->getBlockContext()->getParameter("documentLang");

		if(is_null($documentLang))
		{
			$documentLang = $this->getRequestParameter("docLang");
		}

		if(!is_null($documentId))
		{   
			$tempDocService = m_backoffice_services_TempDocService::getInstance();

			if($tempDocService->hasTemporary($documentId, $documentLang))
			{
				$document = $tempDocService->getTemporaryDocument($documentId, $documentLang);
			}
			else
			{
				$document = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Page', $documentId, $documentLang);			
			}
		}

        if(!$document->hasTemplateFile())
        {
            // @todo Send to a change template action
            return "Template file not found";
        }
        else
        {
            $this->addToModel('page', $document);
            $this->setView('success');
        }
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("website_TabPageStructure", "website_BlockEdit", "website_ValidatePage"), "OR");
	}
}